package com.chenglu.android.goodsinfo.touch;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.chenglu.android.R;
import com.gyf.immersionbar.ImmersionBar;


import java.util.ArrayList;

import me.jessyan.autosize.internal.CustomAdapt;

public class BigImgActivity extends AppCompatActivity implements CustomAdapt {

    private HackyViewPager viewPager;

    private TextView tvNum;

    public static final String IMGDATA = "IMGDATA";
    public static final String IMGSTATU = "IMGSTATUS";


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_big_img);

        ImmersionBar.with(this)
                .statusBarColor(R.color.black)
                .statusBarDarkFont(true)
                .fullScreen(true)
                .init();
        initView();

    }
     ArrayList<String> imgData;

    protected void initView() {

        viewPager = findViewById(R.id.viewPagerNine);
        tvNum = findViewById(R.id.tv_pager);
        //接收图片数据及位置
        int imgstatu = getIntent().getIntExtra(IMGSTATU, 0);
        if(imgstatu == 1001){
            String img = getIntent().getStringExtra("img");
            imgData = new ArrayList<>();
            imgData.add(img);
        }else {
            imgData = getIntent().getStringArrayListExtra("imgData");
        }

        int clickPosition = getIntent().getIntExtra("clickPosition", 0);


//添加适配器

        PhotoPagerAdapter viewPagerAdapter = new PhotoPagerAdapter(getSupportFragmentManager(), imgData);

        viewPager.setAdapter(viewPagerAdapter);

        viewPager.setCurrentItem(clickPosition);//设置选中图片位置


        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override

            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                tvNum.setText(String.valueOf(position + 1) + "/" + imgData.size());

            }


            @Override

            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {


            }

        });

    }

    @Override
    public boolean isBaseOnWidth() {
        return false;
    }

    @Override
    public float getSizeInDp() {
        return 812;
    }
}
